package com.rafal.uczelnia;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class KlientCzasu {
	public static void main(String[] args) {
		Socket socket = null;
		String hostname = "ntp.icm.edu.pl";

		try {
			socket = new Socket(hostname, 13);
			InputStream in = socket.getInputStream();
			StringBuilder data = new StringBuilder();

			int znak;

			while ((znak = in.read()) != -1) {
				data.append((char) znak);
			}
			System.out.println("Na serwerze: " + hostname + " mamy date: "
					+ data.toString().trim());

		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			System.err.println(e);
		} catch (IOException e) {
			System.err.println(e);
		} finally {
			if (socket != null) {
				try {
					socket.close();
				} catch (IOException eio) {
				}
			}
		}

	}
}
